package org.niit.app.offline

import org.apache.spark.sql.SparkSession
import org.niit.service.OfflineAnalysisService

/**
 * 离线分析应用入口
 */
object BatchDataApp {
  def main(args: Array[String]): Unit = {
    // 创建SparkSession
    val spark = SparkSession
      .builder()
      .appName("TakeawayOfflineAnalysis")
      .master("local[*]")
      .config("spark.sql.warehouse.dir", "spark-warehouse")
      .getOrCreate()
    
    // 设置日志级别
    spark.sparkContext.setLogLevel("WARN")
    
    try {
      println("===================== 外卖订单离线分析应用 ======================")
      
      // 数据文件路径
      val dataPath = "F:/code/Takeaway-master/input/takeaway.txt"
      
      // 执行所有离线分析
      OfflineAnalysisService.runAllAnalysis(spark, dataPath)
      
      println("===================== 离线分析完成 =====================")
    } catch {
      case e: Exception =>
        println("离线分析过程中发生错误:")
        e.printStackTrace()
    } finally {
      // 停止SparkSession
      spark.stop()
    }
  }
} 